package com.wzg.web.controller;

import com.wzg.rpc.pojo.TbItem;
import com.wzg.web.service.ManagerItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.EgoResult;
import pojo.PageResult;

import java.math.BigDecimal;
@Controller
public class ItemController {

    //注入service对象
    @Autowired
    private ManagerItemService managerItemService;

    /***
     * 处理商品信息分页查询的请求
     * **/
    @RequestMapping(value="item/list",produces= MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8")
    @ResponseBody
    public PageResult<TbItem> itemList(@RequestParam(defaultValue="1")Integer page,
                                       @RequestParam(defaultValue="30")Integer rows){
        return managerItemService.selectItemListService(page, rows);
    }

    /**
     * 处理商品上架的请求
     * @param ids
     * @return
     */
    @RequestMapping(value="item/reshelf",
            produces=MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8")
    @ResponseBody
    public EgoResult reshelfItem(BigDecimal[] ids){
        return managerItemService.reshelfItem(ids);
    }

    /***
     * 处理商品下架请求
     * **/
    @RequestMapping(value="item/instock",
            produces=MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8")
    @ResponseBody
    public EgoResult instockItem(BigDecimal[] ids){
        return managerItemService.instockItem(ids);
    }

    /***
     * 处理商品信息的删除请求
     * **/
    @RequestMapping(value="item/delete",
            produces=MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8")
    @ResponseBody
    public EgoResult itemDelete(BigDecimal[] ids){
        return managerItemService.delteItemService(ids);
    }
}
